#ifndef __DWARF_LISTENER
#define __DWARF_LISTENER

#include "Ogre.h"
#include "OgreStringConverter.h"
#include "OgreException.h"



#include <OIS/OIS.h>

using namespace Ogre;


namespace GUI
{
	class DwarfGUI;
};

namespace Graphics
{
	class MapRenderer;
};


namespace Main
{

	class Listener: public FrameListener, public WindowEventListener,
					public OIS::MouseListener, public OIS::KeyListener   
	{
	protected:
		void updateStats(void);

	public:
		// Constructor takes a RenderWindow because it uses that to determine input context
		Listener(RenderWindow* win, Camera* cam,GUI::DwarfGUI* gui,Graphics::MapRenderer* mapRenderer, bool bufferedKeys = false, bool bufferedMouse = false );

		//Adjust mouse clipping area
		void windowResized(RenderWindow* rw);
		//Unattach OIS before window shutdown (very important under Linux)
		void windowClosed(RenderWindow* rw);

		~Listener();

		bool processUnbufferedKeyInput(const FrameEvent& evt);
		bool processUnbufferedMouseInput(const FrameEvent& evt);
		void moveCamera();
		void showDebugOverlay(bool show);

		// Override frameStarted event to process that (don't care about frameEnded)
		bool frameStarted(const FrameEvent& evt);
		bool frameEnded(const FrameEvent& evt);

		bool Listener::mouseReleased(const OIS::MouseEvent &arg,OIS::MouseButtonID id);
		bool Listener::mousePressed(const OIS::MouseEvent &arg,OIS::MouseButtonID id);
		bool Listener::mouseMoved(const OIS::MouseEvent &arg);

		bool keyPressed(const OIS::KeyEvent &arg);
		bool keyReleased(const OIS::KeyEvent &arg);

	protected:
		Camera* mCamera;

		Vector3 mTranslateVector;
		RenderWindow* mWindow;
		bool mStatsOn;

		std::string mDebugText;

		unsigned int mNumScreenShots;
		float mMoveScale;
		Degree mRotScale;
		// just to stop toggles flipping too fast
		Real mTimeUntilNextToggle ;
		Radian mRotX, mRotY;
		TextureFilterOptions mFiltering;
		int mAniso;

		int mSceneDetailIndex ;
		Real mMoveSpeed;
		double mAvgFrameTime;
		Degree mRotateSpeed;
		Overlay* mDebugOverlay;

		//OIS Input devices
		OIS::InputManager* mInputManager;
		OIS::Mouse*    mMouse;
		OIS::Keyboard* mKeyboard;

		bool mLBDown;
		GUI::DwarfGUI *mGui;


		Graphics::MapRenderer *mMapRenderer;

	}; // class Listener
}; // namespace Main

#endif
